
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>邀请管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input v-model="formInline.ename" placeholder="邀请企业"></el-input>
      </el-form-item>
      <el-form-item label="搜索：">
        <el-input
          v-model="formInline.username"
          placeholder="客户姓名"
        ></el-input>
      </el-form-item>
      <el-form-item label="搜索：">
        <el-input
          v-model="formInline.phonenum"
          placeholder="客户手机号"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="search"
          >搜索</el-button
        >
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table
      size="small"
      :data="listData"
      highlight-current-row
      v-loading="loading"
      border
      element-loading-text="拼命加载中"
      style="width: 100%"
    >
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column prop="eid" label="邀请企业编号" width="120">
      </el-table-column>
      <el-table-column prop="ename" label="邀请企业名称" width="160">
      </el-table-column>
      <el-table-column sortable prop="username" label="管理员" width="160">
      </el-table-column>
      <el-table-column sortable prop="phonenum" label="管理员手机" width="160">
      </el-table-column>
      <el-table-column sortable prop="estatus" label="邀请企业状态" width="160">
      </el-table-column>
      <el-table-column sortable prop="count" label="邀请次数" width="100">
      </el-table-column>
      <el-table-column
        sortable
        prop="update_time"
        label="最后邀请时间"
        width="160"
      >
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button size="mini" type="success" @click="aggre(scope.row)"
            >同意</el-button
          >
          <el-button size="mini" type="danger" @click="refuse(scope.row)"
            >拒绝</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
    <!-- 编辑界面 -->
  </div>
</template>

<script>
import switchOne from '../../components/switchOne.vue'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      editFormVisible: false,
      defaultProps: {
        children: 'enterprises',
        label: 'ename'
      },
      supplyList: [],
      bankOption: [],
      createNetworkDialog: false,
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      editForm: {
        eid: "",
        ename: "",
        username: "",
        address: "",
        phonenum: "",
        enterprises: [],

      },
      formInline: {
        currentPage: 1,
        pageSize: 10,
        eid: '',
        ename: "",
        phonenum: "",
        username: ""
      },
      // 删除部门
      seletedata: {
        ids: '',
        token: localStorage.getItem('logintoken')
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      },
      //登录企业id
      id: ''
    }
  },
  // 注册组件
  components: {
    Pagination,
    switchOne
  },

  /**
   * 创建完毕
   */
  created() {
    this.id = JSON.parse(localStorage.getItem("userdata")).enterprise_id;
    this.formInline.eid = JSON.parse(localStorage.getItem("userdata")).enterprise_id;
    this.getdata(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    //拒绝邀请
    refuse(row) {
      this.$confirm('确定要拒绝吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$axios.delete('/api/supply/refuse/' + row.eid + '/' + this.id)
            .then(res => {
              console.log();
              if (res.data.code == 200) {
                this.getdata()
                this.$message({
                  type: 'info',
                  message: res.data.message
                })
              }
            })
            .catch(err => {
              this.$message.error('拒绝失败，请稍后再试！')
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    handleSelectionChange(val) {
      this.submitData.enterprises = val;
      console.log(this.submitData.enterprises)
    },
    //同意邀请
    aggre(row) {
      console.log(row)
      //查询核心企业对应的供应链
      this.$axios.get('/api/supply/aggre/' + row.eid + '/' + this.id)
        .then(res => {
          this.getdata()
          if (res.data.code == 200) {
            this.listData = []
            this.getdata()
            this.$message({
              type: 'info',
              message: res.data.message
            })
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('同意失败，请稍后再试！')
        })
    },
    getCheckedKeys2() {
      console.log(this.$refs.tree.getCheckedKeys());
      this.editForm.eids = this.$refs.tree.getCheckedKeys()
    },
    getdata() {
      this.loading = true
      //查询所有邀请
      this.$axios.post('/api/supply/findAllInvite/', this.formInline)
        .then(res => {
          console.log(res);
          this.loading = false
          if (res.data.code == 200) {
            this.$message({
              type: 'info',
              message: res.data.message
            })
            this.listData = res.data.data.list
            // 分页赋值
            this.pageparm.currentPage = this.formInline.currentPage
            this.pageparm.pageSize = this.formInline.pageSize
            this.pageparm.total = res.data.data.total
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('供应链加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.currentPage = parm.currentPage
      this.formInline.pageSize = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.loading = true
      this.$axios.post('/api/supply/findByInvite/', this.formInline)
        .then(res => {
          console.log(res);
          this.loading = false
          if (res.data.code == 200) {
            this.$message({
              type: 'info',
              message: res.data.message
            })
            this.listData = res.data.data.list
            // 分页赋值
            this.pageparm.currentPage = this.formInline.currentPage
            this.pageparm.pageSize = this.formInline.pageSize
            this.pageparm.total = res.data.data.total

          } else {
            this.$message({
              type: 'info',
              message: res.data.message
            })
          }
          this.formInline.ename = ""
          this.formInline.phonenum = ""
          this.formInline.username = ""

        })
        .catch(err => {
          this.loading = false
          this.$message.error('供应链查询失败，请稍后再试！')
        })
    }

  }
}
</script>

<style scoped>
.el-row {
  margin-bottom: 20px;
  /* &:last-child {
    margin-bottom: 0;
  } */
}
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
.create-course-dialog .el-dialog {
  margin-top: 40px !important;
  width: 1000px;
  height: 820px;
  position: relative;
}
.create-course-dialog .el-upload {
  width: 100px;
  position: relative;
  left: 5px;
  top: 5px;
}
.create-course-dialog img {
  width: 100%;
  height: 100%;
}
.create-course-dialog .el-dialog__title {
  font-size: 30px;
}
.create-course-dialog .el-form-item__label {
  font-size: 18px;
  width: 90px;
}
.create-course-dialog .el-form-item {
  margin-top: 10px;
}
.create-course-dialog .el-input {
  width: 250px;
}
.create-course-dialog .dialog-left {
  float: left;
  border: 1px #bababa solid;
  border-radius: 5px;
  width: 420px;
  height: 380px;
  position: relative;
}
.create-course-dialog .dialog-right {
  float: right;
  border: 1px #bababa solid;
  border-radius: 5px;
  width: 500px;
  height: 380px;
}
.create-course-dialog .dialog-footer {
  position: absolute;
  bottom: 20px;
  right: 30px;
}
.create-course-dialog .el-input-number .el-input {
  width: 100%;
}
.create-course-dialog .el-input-number {
  width: 100px;
}
.create-course-dialog .el-form-item__error {
  margin-left: 90px;
}
.el-popover {
  max-width: 860px;
  max-height: 760px;
  overflow: auto;
}
.small-img img {
  height: 100px;
}
.small-img {
  padding: 5px;
  float: left;
}
</style>


